请高手帮小弟更正一下错误`

来源:百度知道 编辑:UC知道 时间:2024/05/24 19:05:18
1、运输公司对用户计算运费。路程(s)越远,每公里的运费越低。收费标准如下:
S<250km 无折扣
250<=s<500 2%折扣
500<=s<1000 5%折扣
1000<=s<2000 8%折扣
2000<=s<3000 10%折扣
3000<=s 15%折扣

设每公里每吨货物的基本运费为p(price的缩写),货物重为w(weight的缩写),距离为s,折扣为d(discount的缩写),则总运费f(freight的缩写)的计算公式为:
f = p * w * s * (1 - d)

请编程实现总运费f的计算——p、、w、s的值由键盘输入。(程序验证:当p=100,w=20,s=300时,f=588000。)

我的编程:
#include<iostream.h>
int main()
{
float p,w,s,d,f;
f=p*w*s*(1-d);
cout<<"enter the p,w,s:";
cin>>p>>w>>s;
{if(s<250)
cout<<"d=0"<<endl;
else if(s>=250&&s<500)
cout<<"d=0.02"<<endl;
else if(s>=500&&s<1000)
cout<<"d=0.05"<<endl;
else if(s>=1000&&s<2000)
cou

#include<iostream.h>
int main()
{
float p,w,s,d,f;
//f=p*w*s*(1-d);//这句不要,计算要在最后进行。
cout<<"enter the p,w,s:";
cin>>p>>w>>s;
{if(s<250)
cout<<"d=0"<<endl;
else if(s<500)//条件判断可以简化,下同
cout<<"d=0.02"<<endl;
else if(s<1000)
cout<<"d=0.05"<<endl;
else if(s<2000)
cout<<"d=0.08"<<endl;
else if(s<3000)
cout<<"d=0.1"<<endl;
else
cout<<"d=0.15"<<endl;
}
f=p*w*s*(1-d);//在这里进行计算。
cout<<f<<endl;

return 0;
}

//错在没给d值,还有else if 的范围表达不标准,要给d 赋值了才能带公式计算,所以把公式放到后面去

#include<iostream.h>
int main()
{
float p,w,s,d;
int f;

cout<<"enter the p,w,s:";
cin>>p>>w>>s;
{if(s<250)
{d=0